<!--必要的组件说明-->
<!-- -->
<!-- author:yewenjie. date:2024/4/17 10:06-->
<template>
  <div class='index'>
    <div class="top_title">
      <div
        class="top_title_back"
        @click="$router.go(-1)"
      ><i class="iconfont icon-back"></i></div>
      <div class="top_title_val">
        {{ $route.meta.title }}
      </div>
    </div>
<!--    <van-nav-bar
      :fixed="true"
      :placeholder="true"
      :title="$route.meta.title"
      left-text="返回"
      left-arrow
      @click-left="$router.go(-1)"
    />-->

    <van-cell center title="自动检测图片中车牌号码">
      <template #right-icon>
        <van-switch v-model="form.isCarNo" size="24" @change='addUpdate' />
      </template>
    </van-cell>
    <van-cell center title="车牌号码自动匹配系统车架号">
      <template #right-icon>
        <van-switch v-model="form.isVinNum" size="24" @change='addUpdate' />
      </template>
    </van-cell>

  </div>
</template>

<script>
import Vue from 'vue'
import axios from 'axios'
import qs from 'qs'
const base_url = process.env.BASE_API;
import { getCookies } from "@/utils/util.js";
import repairApi from "@/api/repairApi";
import { Notify } from 'vant'
export default {
  name: 'index',
  components: {},
  data() {
    return {
      form:{
        id:'',
        isCarNo: true,
        isVinNum: true
      }
    }
  },
  methods: {
    // 获取外部联系人信息
    configData() {
      axios({
        url: `${base_url}/proxy/baokt/config/data`,
        method: "post",
        data: qs.stringify(
          { personId: JSON.parse(getCookies('userInfo')).kdpersonid},
          { encode: true }
        ),
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          satoken: getCookies("token"),
        },
      }).then((res) => {
        console.log("获取保客通外服登记配置信息:", res.data);
        if (res.data && res.data.data && res.data.data.length != 0) {
            this.form.id = res.data.data.id
            this.form.isCarNo = res.data.data.isCarNo ? true : false
            this.form.isVinNum = res.data.data.isVinNum ? true : false
        }else if(!res.data.success) {
          Notify({ type: 'danger', message: res.data.errorMessage })
        }
      });
    },

    // 新增修改外服登记配置信息
    addUpdate() {
      console.info(this.form)
      let param = {
        id : this.form.id,
        isCarNo : this.form.isCarNo ? 1 : 0,
        isVinNum : this.form.isVinNum ? 1 : 0,
        personId : JSON.parse(getCookies('userInfo')).kdpersonid
      }
      repairApi.
        configAddUpdate(param).then((res) => {
          console.info(res)
        if(res && res.errorCode === '-1'){
          Notify({ type: 'danger', message: res.errorMessage })
        } else {
          Notify({ type: 'success', message: '修改成功' })
          this.configData()
        }
      })
    }
  },
  filters: {},
  computed: {},
  props: [],
  watch: {},
  created() {
    this.configData()
  },
  mounted() {
  }
}
</script>

<style scoped lang='less'>

.index {
  width: 100%;
  height: 100%;
  background: #f3f3f3;

  .top_title {
    position: relative;
    width: 100%;
    height: 50px;
    background: url(../../assets/images/title_bg.png) no-repeat;
    background-size: 100%;
    background-attachment: fixed;

    .top_title_back {
      position: absolute;
      left: 10px;
      line-height: 50px;
      color: #fff;
      font-size: 16px;
    }

    .top_title_val {
      text-align: center;
      line-height: 50px;
      color: #fff;
      font-weight: bold;
      font-size: 16px;
    }
  }

  /deep/ .van-cell::after{
    left: 0;
    right: 0;
  }
  .submitBtn {
    background: #1174d6;
    text-align: center;
    font-size: 0.3rem;
    padding: 0.3rem 0;
    width: 90%;
    margin: 0.5rem auto;
    color: #fff;
    border-radius: 5px;
  }
}

</style>
